package com.base.web.restful.controller;

import com.base.web.core.common.JsonResult;
import com.base.web.model.master.auth.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description: Restful 接口整合swagger2 controller层例子
 *
 * @Author: RenTie
 * @Date: 2018-08-16 10:07
 **/
@Api("restful接口示范")
@RestController
@RequestMapping("/api")
public class RestfulApiController {

    private Logger logger = LoggerFactory.getLogger(RestfulApiController.class);

    @ApiOperation(value="获取对象列表", notes="获取对象列表")
    @GetMapping(value = "/objects")
    public JsonResult getList(){

        return JsonResult.success("objects");
    }

    @ApiOperation(value="获取单个对象", notes="获取单个对象")
    @GetMapping(value = "/object/{id}")
    public JsonResult getOne(@ApiParam(name = "id",value = "对象id") @PathVariable("id")String id){

        return JsonResult.success(id);
    }

    @ApiOperation(value="添加对象", notes="添加对象")
    @PostMapping(value = "/object")
    public JsonResult addOne(@ApiParam(name = "user",value = "User")User user){

        return JsonResult.success("objects");
    }

    @ApiOperation(value="修改对象", notes="修改对象")
    @PutMapping(value = "/object")
    public JsonResult editOne(@ApiParam(name = "user",value = "User")User user){

        return JsonResult.success("objects");
    }

    @ApiOperation(value="删除单个对象", notes="删除单个对象")
    @DeleteMapping(value = "/object/{id}")
    public JsonResult deleteOne(@ApiParam(name = "id",value = "对象id") @PathVariable("id")String id){

        return JsonResult.success(id);
    }

}
